-
Notifications
You must be signed in to change notification settings - Fork 27.4k
fix($parse): standardize one-time literal vs non-literal and interceptors #15858
Conversation
fbb62fa
to
a0bb123
Compare
src/ng/directive/ngClass.js
Outdated
@@ -97,15 +90,9 @@ function classDirective(name, selector) { | |||
oldModulo = newModulo; | |||
} | |||
|
|||
function ngClassOneTimeWatchAction(newClassValue) { | |||
function ngClassWatchAction(newClassValue) { | |||
var newClassString = toClassString(newClassValue); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since toClassString
is being used as an interceptor, is it necessary to pass it through toClassString
again here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you're correct, updated...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately we were wrong. In the case of one-time bindings the pre-interceptor value is returned up until that value passes the one-time test:
Line 1933 in 2b0c050
return isDefined(value) ? result : value; |
I've updated it to do this toClassString
conditionally and added a comment.
} | ||
function isAllDefined(value) { | ||
var allDefined = true; | ||
forEach(value, function(val) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Not directly related to this PR, but I think it makes sense to exit early once an undefined value is found.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think value
can be an object or array which forEach
currently handles or us. Did you have something in mind?
Since this is currently only used for object/array literal cases, we could split this into separate object/array helper methods (one using for-in one using array.every?)...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree it is not worth it. It is just for one-time literals and it will only matter if one has huge literals which don't settle quickly (a very unlikely usecase).
775281c
to
1ef435b
Compare
…tors Previously literal one-time bindings did not use the expression `inputs`, causing infinite digest issues with literal values. This often forces the use of deepEquals when watching one-time literals. `ng-class` is one example of deepEquals which is no longer required. This one-time/literal behavior is now also consistently propogated through interceptors.
1ef435b
to
a58a052
Compare
src/ng/directive/ngClass.js
Outdated
if (newClassString !== oldClassString) { | ||
ngClassWatchAction(newClassString); | ||
function ngClassWatchAction(newClassString) { | ||
//When using a one-time binding the newClassString will return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You realy don't like spaces after //
, do you 😛
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bad (or just different!) habit I guess :)
src/ng/directive/ngClass.js
Outdated
function ngClassWatchAction(newClassString) { | ||
//When using a one-time binding the newClassString will return | ||
//the pre-interceptor value until the one-time is complete | ||
if (newClassString && typeof newClassString !== "string") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just !isString(newClassString)
?
Also, I don't think it makes much difference over always applying toClassString()
(which just does isArray()
and isObject()
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated to isString
. I kind of like an if
block just so it's obvious that the comment applies to the full block, nothing more nothing less...
src/ng/parse.js
Outdated
@@ -1859,6 +1859,7 @@ function $ParseProvider() { | |||
} | |||
|
|||
function oneTimeWatchDelegate(scope, listener, objectEquality, parsedExpression, prettyPrintExpression) { | |||
var doneCriteria = parsedExpression.literal ? isAllDefined : isDefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could have a better name, e.g. isDone
, fulfillsDoneCriteria
, because it's not very descriptive when called later on
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, done.
I think this is ready, PTAL. |
So there's good news and bad news. 👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there. 😕 The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that they're okay with their commits being contributed to this project. Please have them confirm that here in the pull request. Note to project maintainer: This is a terminal state, meaning the |
1 similar comment
So there's good news and bad news. 👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there. 😕 The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that they're okay with their commits being contributed to this project. Please have them confirm that here in the pull request. Note to project maintainer: This is a terminal state, meaning the |
…tors Previously literal one-time bindings did not use the expression `inputs`, causing infinite digest issues with literal values. This often forces the use of deepEquals when watching one-time literals. `ng-class` is one example of deepEquals which is no longer required. This one-time/literal behavior is now also consistently propogated through interceptors. Closes #15858
Previously literal one-time bindings did not use the expression
inputs
, causing infinite digest issues with literal values. This often forces the use of deepEquals when watching one-time literals.ng-class
is one example of deepEquals which is no longer required (and had to be updated to keep all tests passing).This one-time/literal behavior is now also consistently propagated through interceptors (and had to be updated to keep all tests passing).
The ngClass/interceptor part was not originally planned but had to be changed to keep tests passing. Maybe this can be split into smaller commits? But it's mainly just deleting...!